package com.zyc.app.woa.activity;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.MenuItem;
import com.umeng.analytics.MobclickAgent;
import com.zyc.app.woa.R;
import com.zyc.app.woa.fragment.BaseFragment;
import com.zyc.app.woa.utils.FragmentUtil;
import com.zyc.app.woa.utils.FragmentUtil.IFragmentLauncher;

/**
 * Author: yingchang.zhang
 * Date  : 2014/8/9
 */
public class BaseActivity extends FragmentActivity implements IFragmentLauncher {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getActionBar().setDisplayHomeAsUpEnabled(true);
        getActionBar().setHomeButtonEnabled(true);
    }

    @Override
    public boolean onMenuItemSelected(int featureId, MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                onBackPressed();
                return true;
            default:
                break;
        }
        return false;
    }

    @Override
    protected void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }

    @Override
    public void launchFragment(int viewId, BaseFragment fragment) {
        FragmentUtil.launchFragment(getSupportFragmentManager(), viewId, true, fragment);
    }

    @Override
    public void launchFragment(BaseFragment fragment) {
        launchFragment(R.id.fragment_container, fragment);
    }

    public void launchFragmentNoHistory(BaseFragment fragment) {
        FragmentUtil.launchFragment(getSupportFragmentManager(), R.id.fragment_container, false, fragment);
    }
}
